@extends('user.public')

@section('content')
    <div class="col-md-12">
        <form data-validate="parsley" method="post" enctype="multipart/form-data">
            {!! csrf_field() !!}
            <section class="panel panel-default">
                <header class="panel-heading">
                    {{ $chunk->name }} {{ $frame['title'] }}
                    <a href="{{ route('user.chunk.info',$chunk->id) }}"
                       class="btn btn-xs btn-default pull-right">信息列表</a>
                </header>
                <div class="panel-body">
                    <div class="form-group">
                        <label>信息图片</label>
                        <input id="kv-explorer" type="file" multiple name="image">
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-md-8">
                            <label>信息标题</label>
                            <input type="text" class="form-control parsley-validated" data-required="true" name="name">
                        </div>
                        <div class="col-md-4">
                            <label>信息排序</label>
                            <div class="clearfix"></div>
                            <input class="slider slider-horizontal form-control" type="text" value="1"
                                   data-slider-min="1" data-slider-max="50" data-slider-step="1" data-slider-value="1"
                                   data-slider-orientation="horizontal" name="xindex">
                        </div>
                    </div>
                    <input type="hidden" name="theme" value="{{ $chunk['info_theme'] }}">
                    <div class="form-group">
                        <label>信息分类</label>
                        <div class="clearfix"></div>
                        <input type="hidden" name="sort" value="">
                        <select style="width:100%" multiple class="chosen-select srcsort">
                            @if( !empty($sorts) )
                                @foreach( $sorts as $sortlv1 )
                                    <option value="{{ $sortlv1['id'] }}">{{ $sortlv1['name'] }}</option>
                                    @if( !empty($sortlv1['children']) )
                                        @foreach( $sortlv1['children'] as $sortlv2 )
                                            <option style="text-indent: 20px"
                                                    value="{{ $sortlv2['id'] }}">{{ $sortlv2['name'] }}</option>
                                            @if( !empty($sortlv2['children']) )
                                                @foreach( $sortlv2['children'] as $sortlv3 )
                                                    <option style="text-indent: 40px" value="{{ $sortlv3['id'] }}">
                                                        {{ $sortlv3['name'] }}</option>
                                                    @if( !empty($sortlv3['children']) )
                                                        @foreach( $sortlv3['children'] as $sortlv4 )
                                                            <option style="text-indent: 60px"
                                                                    value="{{ $sortlv4['id'] }}">
                                                                {{ $sortlv4['name'] }}</option>
                                                            @if( !empty($sortlv4['children']) )
                                                                @foreach( $sortlv4['children'] as $sortlv5 )
                                                                    <option style="text-indent: 80px"
                                                                            value="{{ $sortlv5['id'] }}">
                                                                        {{ $sortlv5['name'] }}</option>
                                                                @endforeach
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                @endforeach
                                            @endif
                                        @endforeach
                                    @endif
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class="form-group">
                        <label>信息标签</label>
                        <div class="clearfix"></div>
                        <input name="tag" id="tagsinput_tag" class="tagsinput" type="text"
                               value="{{ $tag }}"/>
                    </div>
                    <div class="form-group">
                        <label>摘要信息</label>
                        <textarea class="form-control" name="simpledescribe"
                                  placeholder="企业信息摘要 (如未填写,则引用详细信息中的前部分信息)"></textarea>
                    </div>
                    <div class="form-group">
                        <label>详细信息</label>
                        <div id="describe" name="describe" type="text/plain" style="width: 100%;height: 300px;"></div>
                    </div>
                    @if(array_search('jump_url',$chunk->extends) !== false)
                        <div class="form-group">
                            <label>页面跳转</label>
                            <input type="text" class="form-control parsley-validated" name="jump_url">
                        </div>
                    @endif
                    @if(array_search('price',$chunk->extends) !== false)
                        <div class="form-group">
                            <label>价格</label>
                            <input type="text" class="form-control parsley-validated" name="price" data-required="true">
                        </div>
                    @endif
                    @if(array_search('original_price',$chunk->extends) !== false)
                        <div class="form-group">
                            <label>原价</label>
                            <input type="text" class="form-control parsley-validated" name="original_price"
                                   data-required="true">
                        </div>
                    @endif
                    @if(array_search('sale',$chunk->extends) !== false)
                        <div class="form-group">
                            <label>销量</label>
                            <input type="text" class="form-control parsley-validated" name="sale" data-required="true">
                        </div>
                    @endif
                    <div class="form-group pull-in clearfix">
                        @if(array_search('set_time_out',$chunk->extends) !== false)
                            <div class="col-md-6">
                                <label>定时显示</label>
                                <div class="clearfix"></div>
                                <input class="input-sm input-s datepicker-input form-control" name="set_time_out"
                                       size="16"
                                       type="text" value="{{ date('Y-m-d',time()+24*3600) }}"
                                       data-date-format="yyyy-mm-dd">
                            </div>
                        @endif
                        @if(array_search('file',$chunk->extends) !== false)
                            <div class="col-md-6">
                                <label>文件上传</label>
                                <div class="clearfix"></div>
                                <input type="file" name="file" class="filestyle" data-icon="false"
                                       data-classButton="btn btn-default"
                                       name="web_qrcode"
                                       data-classInput="form-control inline v-middle input-s">
                            </div>
                        @endif
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_new"
                                   class="parsley-validated"><i></i> 勾选此项,此信息即为最新信息
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_push"
                                   class="parsley-validated"><i></i> 勾选此项,此信息即为推荐信息
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_hot"
                                   class="parsley-validated"><i></i> 勾选此项,此信息即为热门信息
                        </label>
                    </div>
                </div>
                <footer class="panel-footer text-right bg-light lter">
                    <button type="submit" class="btn btn-success btn-s-xs gatherInfo">保存</button>
                </footer>
            </section>
        </form>
    </div>
@endsection

@section('css')
    <link rel="stylesheet" href="/public/theme/js/slider/slider.css" type="text/css"/>
    <link href="/public/fileinput/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
    <link href="/public/fileinput/themes/explorer/theme.css" media="all" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="/public/theme/js/chosen/chosen.css" type="text/css"/>
    <link rel="stylesheet" href="/public/theme/js/datepicker/datepicker.css" type="text/css"/>

@endsection

@section('js')
    <!-- datepicker -->
    <script src="/public/theme/js/datepicker/bootstrap-datepicker.js"></script>

    <!-- parsley -->
    <script src="/public/theme/js/parsley/parsley.min.js"></script>
    <script src="/public/theme/js/parsley/parsley.extend.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/jquery.jplayer.min.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/add-on/jplayer.playlist.min.js"></script>
    <script type="text/javascript" src="/public/theme/js/jPlayer/demo.js"></script>

    <!-- Chosen -->
    <script src="/public/theme/js/chosen/chosen.jquery.min.js"></script>

    <!-- slider -->
    <script src="/public/theme/js/slider/bootstrap-slider.js"></script>

    <!-- uediter -->
    <script src="/public/laravel-u-editor/ueditor.config.js"></script>
    <script src="/public/laravel-u-editor/ueditor.all.min.js"></script>
    <script src="/public/laravel-u-editor/lang/zh-cn/zh-cn.js"></script>

    <!-- fileinput -->
    <script src="/public/fileinput/js/plugins/sortable.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/fileinput.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/locales/zh.js" type="text/javascript"></script>
    <script src="/public/fileinput/js/locales/es.js" type="text/javascript"></script>
    <script src="/public/fileinput/themes/explorer/theme.js" type="text/javascript"></script>

    <!-- tagsinput -->
    <script src="/public/theme/js/tagsinput/bootstrap-switch.js"></script>
    <script src="/public/theme/js/tagsinput/jquery.tagsinput.js"></script>
    <script src="/public/theme/js/tagsinput/form-component.js"></script>

    <!-- file input -->
    <script src="/public/theme/js/file-input/bootstrap-filestyle.min.js"></script>

    <script>
        $(document).ready(function () {
            $("#kv-explorer").fileinput({
                uploadUrl: '{{ route('admin.info.addimage',$chunk->path) }}',
                allowedFileExtensions: ['jpg', 'png', 'gif'],
                language: 'zh',
                browseOnZoneClick: true,
                maxFileCount: {{ config('app.maxFileCount') }},
                minFileCount:{{ config('app.minFileCount') }},
                uploadAsync: true,
                theme: 'explorer',
                overwriteInitial: false,
                initialPreviewAsData: true,
            });
            $("#kv-explorer").on("fileuploaded", function (event, data, previewId, index) {
                if (data.response.status) {
                    $('#' + previewId).attr('delete-id', data.response.image_id).append('<input type="hidden" name="images[]" value="' + data.response.image_id + '" />');
                }
            })
            $('#kv-explorer').on('filesuccessremove', function (event, id) {
                var d = true;
                //得到要删除的图片的id
                var deleteId = $('#' + id).attr('delete-id');
                $.post('{{ url('admin/info/delimage') }}', {'key': deleteId, 'type': 'image'}, function (data) {
                    eval(' d = ' + data);
                    if (d.status) {
                        $('#' + id).remove();
                    }
                });
                return false;
            });
        });
    </script>
    <script>
        $('.gatherInfo').click(function () {
            var need = '';
            $('a.search-choice-close').each(function () {
                var order = $(this).attr('data-option-array-index');
                var id = $('.srcsort').find('option:eq(' + order + ')').val();
                need += id + ',';
            })
            $('input[name="sort"]').val(need);
        });
    </script>
    <script>
        var uea = UE.getEditor('describe');
    </script>
    <script>
        @if(!empty($sort))
        $('.srcsort').find('option[value="{{ $sort }}"]').attr('selected', 'selected');
        @else
        $('.srcsort').find('option:eq(0)').attr('selected', 'selected');
        @endif
    </script>
@endsection
